package com.example;

/**
 * @desc:
 * @author: Shoko
 * @date: 2025/6/1
 */
// ChatServer.java
import java.io.*;
import java.net.*;
import java.util.*;

public class ChatServer {
    private ServerSocket serverSocket;
    private ChatGroup chatGroup;

    public ChatServer(int port) throws IOException {
        serverSocket = new ServerSocket(port);
        chatGroup = new ChatGroup();
        System.out.println("聊天室服务器启动，监听端口: " + port);
    }

    public void start() {
        while (true) {
            try {
                Socket clientSocket = serverSocket.accept();
                new ClientHandler(clientSocket, chatGroup).start();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) throws IOException {
        ChatServer server = new ChatServer(12345);
        server.start();
    }
}